<?php namespace Common\Model;

use Hdphp\Model\Model;

//职位表
class Job extends Model{
	//定义模型
	protected $table = "job";
	//自动验证
	protected $validate=array(
		array('jname','required','职位名不能为空',3,3),
		array('salary','required','薪酬不能为空',3,3),
		array('experience','required','工作经验不能为空',3,3),
		array('education','required','学历要求不能为空',3,3),
		array('benefit','required','职位诱惑不能为空',3,3),
		array('jobaddress','required','详细工作地点不能为空',3,3),
		array('jobtype','required','工作类型不能为空',3,3),
		array('lg_company_gsid','required','请先开通招聘服务',3,3),
		array('lowmoney','required','薪酬不能为空',3,3),
		array('topmoney','required','薪酬不能为空',3,3),
	);
	//自动完成
	protected $auto=array(
		array('jobsendtime','time','function',3,1),
	);

	//发布职位
	public function store(){
		if (!$this->create()) return false;
		//验证职位数据表
		$jobDataModel=new \Common\Model\JobData;
		if (!$jobDataModel->create()) {
			$this->error=$jobDataModel->getError();
			return false;
		}
		$jid=$this->add();
		//添加职位数据表
		$jobDataModel->data['lg_job_jid']=$jid;
		$jobDataModel->add();
		//公司职位数量自增
		$companyModel=new \Common\Model\Company;
		$uid=$_SESSION['homeInfo']['uid'];
		$companyModel->where('lg_user_uid',$uid)->increment('jobnumber',1);
		return true;
	}

	//编辑职位
	public function edit(){
		if (!$this->create()) return false;
		//验证职位数据表
		$jobDataModel=new \Common\Model\JobData;
		if (!$jobDataModel->create()) {
			$this->error=$jobDataModel->getError();
			return false;
		}
		$this->save();
		$jid=Q('get.jid');
		$jobDataModel->where("lg_job_jid={$jid}")->save();
		return true;
	}



}